<template>
    <div class="box">
        <el-row>
            <el-col :span="22" :push="1">
                <div class="grid-content bg-purple" style="height: 77px">
                    <span style="line-height: 77px; font-size: 14px"> </span>
                    <span style="margin-left: 20px">
                        <el-button type="primary" size="small" @click="addMaintain">添加保养记录</el-button>
                    </span>
                </div>
            </el-col>
        </el-row>
        <!-- 搜索栏start -->
        <el-row>
            <el-col :span="22" :push="1">
                <div class="grid-content bg-purple">
                    <div style="width: 100%; margin-left: 20px;">
                        <span style="margin-left: 20px;">
                            <el-form :inline="true" :model="formInline" size="mini" class="demo-form-inline">
                                <el-form-item label="车牌号">
                                    <el-select v-model="formInline.carNumber" placeholder="车牌号">
                                        <span v-for="(item, index) in carNumbers" :key="index">
                                            <el-option :label="item.carNumber" :value="item.carNumber"></el-option>
                                        </span>
                                    </el-select>
                                </el-form-item>
                                <el-form-item label="保养时间">
                                    <el-date-picker v-model="formInline.maintainTime" value-format="yyyy-MM-dd" format="yyyy-MM-dd" type="date" placeholder="选择日期">
                                    </el-date-picker>
                                </el-form-item>
                                <el-form-item label="下次保养时间">
                                    <el-date-picker v-model="formInline.maintainEndtime" value-format="yyyy-MM-dd" format="yyyy-MM-dd" type="date" placeholder="选择日期">
                                    </el-date-picker>
                                </el-form-item>
                                <el-form-item>
                                    <el-button type="primary" @click="onSubmit">搜索</el-button>
                                    <el-button type="primary" @click="reset">重置</el-button>
                                </el-form-item>
                            </el-form>
                        </span>
                    </div>
                </div>
            </el-col>
        </el-row>
        <!-- 搜索栏end -->
        <!-- 表格 -->
        <el-row>
            <el-col :span="22" :push="1">
                <div class="grid-content bg-purple">
                    <span style="padding-left: 10px">
                        <el-table :data="tableData" border="" style="width:100%;">
                            <el-table-column fixed prop="carNumber" label="车牌号" width="100">
                            </el-table-column>
                            <el-table-column prop="maintainTime" label="保养时间" width="160">
                            </el-table-column>
                            <el-table-column prop="maintainMoney" label="费用" width="100">
                            </el-table-column>
                            <el-table-column prop="mileage" label="历程" width="100">
                            </el-table-column>
                            <el-table-column prop="maintainItem" label="保养项目" width="140">
                                <template slot-scope="scope">
                                    <span v-if="scope.row.maintainItem.includes(0)">
                                    发动机机油;
                                    </span>
                                    <span v-if="scope.row.maintainItem.includes(1)">
                                    刹车油;
                                    </span>
                                    <span v-if="scope.row.maintainItem.includes(2)">
                                    空气滤清器;
                                    </span>
                                    <span v-if="scope.row.maintainItem.includes(3)">
                                    空调冷冻液;
                                    </span>
                                    <span v-if="scope.row.maintainItem.includes(4)">
                                    发动机清洗;
                                    </span>
                                    <span v-if="scope.row.maintainItem.includes(5)">
                                    机箱清洗;
                                    </span>
                                </template>
                            </el-table-column>
                            <el-table-column prop="nickName" label="添加人" width="100">
                            </el-table-column>
                            <el-table-column prop="maintainEndtime" label="下次保养时间" width="120">
                            </el-table-column>
                            <el-table-column prop="createTime" label="添加时间" width="170">
                            </el-table-column>
                            <el-table-column fixed="right" label="操作" width="140">
                                <template slot-scope="scope">
                                    <el-button @click="updateClick(scope.row.id)" type="text"
                                        size="small">修改</el-button>
                                    <el-button @click="delClick(scope.row.id)" type="text" size="small">删除</el-button>
                                </template>
                            </el-table-column>
                        </el-table>
                        <div class="grid-content bg-purple-dark">
                            <div class="block">
                                <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
                                    :current-page="pageNum" :page-sizes="[5, 10, 20, 50]" :page-size="pageSize"
                                    layout="total, sizes, prev, pager, next, jumper" :total="total">
                                </el-pagination>
                            </div>
                        </div>
                    </span>
                </div>
            </el-col>
        </el-row>
    </div>
</template>

<script>
import axios from 'axios'
export default {
    data() {
        return {
            //搜索
            formInline: {},
            //拒绝 同意
            from: {},
            pageNum: 1,
            pageSize: 5,
            total: 1,
            tableData: [],
            carNumbers: [],
        }
    },
    created() {
        this.getCarNumber()
        this.findCarcheer()
    },
    methods: {
        //修改
        updateClick(id) {
            this.$router.push({ path: "/addmaintain", query: { id: id } })
        },
        //删除
        delClick(id) {
            axios.post("carmaintain/delMaintain?id=" + id).then((res) => {
                console.log(res)
                if (res.data.code === 200) {
                    this.$message.success(res.data.data)
                    this.findCarcheer()
                }
            })
        },
        // 查询加油记录
        findCarcheer() {
            axios.post("carmaintain/findCarcheerPagination?pageSize=" + this.pageSize + "&pageNum=" + this.pageNum, this.formInline).then((res) => {
                console.log(res)
                this.tableData = res.data.data.records
                this.total = res.data.data.total
            })
        },
        //添加加油记录
        addMaintain() {
            this.$router.push("/addmaintain")
        },
        //搜索
        onSubmit() {
            this.findCarcheer()
            this.$message.success("查询完成")
        },
        //查询车牌号
        getCarNumber() {
            axios.get("/car/getCarNumber").then((res) => {
                console.log(res)
                this.carNumbers = res.data.data
            })
        },
        //重置
        reset() {
            this.formInline = {}
            this.timeArr = []
            this.findCarcheer()
        },
        //每页条数改变时触发 选择一页显示多少行
        handleSizeChange(val) {
            this.pageSize = val;
            this.findCarcheer();
        },
        //当前页改变时触发 跳转其他页
        handleCurrentChange(val) {
            this.pageNum = val;
            this.findCarcheer();
        },
    }
}
</script>

<style scoped>
/* element-ui样式 */
.el-row {
    margin-bottom: 10px;

    &:last-child {
        margin-bottom: 0;
    }
}

.el-col {
    border-radius: 4px;
}

.bg-purple {
    background: #fff;
    border-radius: 10px;
}

/* 自定义样式 */
/* * {
    margin: 0px;
    padding: 0px;
  } */
.box {
    width: 98%;
    height: 100%;
    margin: auto;
    /* background-color: red; */
}
</style>